package com.hfi.security.core.authentication.authorize;

import com.hfi.security.core.properties.SecurityConstants;
import com.hfi.security.core.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component;

/**
 * @author ChangLiang
 * @date 2019/9/8
 */
@Component
public class CoreAuthorizeConfigProvider implements AuthorizeConfigProvider {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public boolean config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        config.antMatchers(
                // login_page默认配置
                SecurityConstants.DEFAULT_LOGIN_PAGE_URL,
                // 避免authentication/require 重定向过多
                SecurityConstants.DEFAULT_UNAUTHENTICATION_URL,
                // /authentication/mobile
                SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_MOBILE,
                // /code/*
                SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/*",
                // 应用级配置 在jpaDemo项目中配置login_page
                securityProperties.getBrowser().getLoginPage(),
                "/hfi-register.html",
                "/hfi-setPassword.html",
                "/register",
                "/setPassword",
                // demo-signUp.html
                securityProperties.getBrowser().getSignUpUrl(),
                securityProperties.getBrowser().getSession().getSessionInvalidUrl(),
                "/hfi-logout.html",
                // 返回给前端用户信息
                "/social/signUp"
        ).permitAll();
        return false;
    }
}
